/**
 * ----------------------------------------------------------------
 * 权限配置
 *
 * 系统权限唯一入口
 * 配合router权限过滤，只需要对二级菜单配置权限
 *
 * ---------------------------------------------------------------- */

import { prefixAuth as PREFIX_AUTH } from '@/env'

function createAuthString (prefixAuth, action) {
  action = typeof action === 'string' ? action.split(/ +/g) : action
  return action.reduce((t, n) => {
    t[n] = `${PREFIX_AUTH}.${prefixAuth}:${n}`
    return t
  }, {})
}

// 控制面板 / 菜单
const dashboard = createAuthString('dashboard', ['menu'])

// 反馈信息 / 菜单
const feedback = createAuthString('feedback', ['menu'])

// 业务配置
const business = {
  // 维保供应商
  maintenanceSupplier: createAuthString('business.maintenanceSupplier', ['menu', 'create', 'update', 'delete']),
  // 维保商品分类
  maintenanceCategory: createAuthString('business.maintenanceCategory', ['menu', 'create', 'update', 'delete']),
  // 维保商品
  maintenanceGoods: createAuthString('business.maintenanceGoods', ['menu', 'create', 'update', 'delete']),
  // 生鲜供应商
  freshSupplier: createAuthString('business.freshSupplier', ['menu', 'create', 'update', 'delete']),
  // 生鲜商品分类
  freshCategory: createAuthString('business.freshCategory', ['menu', 'create', 'update', 'delete']),
  // 生鲜商品
  freshGoods: createAuthString('business.freshCategory', ['menu', 'create', 'update', 'delete']),
  // 团长信息
  commander: createAuthString('business.commander', ['menu', 'create', 'update', 'delete']),
  // 社区信息
  communityInfo: createAuthString('business.communityInfo', ['menu', 'create', 'update', 'delete']),
  // banner配置
  banners: createAuthString('business.banners', ['menu', 'create', 'update', 'delete'])
}

// 订单管理
const orders = {
  // 维保订单
  maintenanceSupplier: createAuthString('orders.maintenanceSupplier', ['menu']),
  // 维保运营者订单
  maintenanceManage: createAuthString('orders.maintenanceManage', ['menu']),
  // 生鲜供应商订单
  freshSupplier: createAuthString('orders.freshSupplier', ['menu']),
  // 生鲜运营者订单
  freshManage: createAuthString('orders.freshManage', ['menu']),

  // 生鲜销量单
  freshManageSales: createAuthString('orders.freshManageSales', ['menu']),
  // 生鲜销量单团长
  freshManageSalesCommander: createAuthString('orders.freshManageSalesCommander', ['menu']),
  // 生鲜供应商销量单
  freshSupplierSales: createAuthString('orders.freshSupplierSales', ['menu']),
  // 生鲜供应商销量单团长
  freshSupplierSalesCommander: createAuthString('orders.freshSupplierSalesCommander', ['menu'])
}

// 系统设置
const system = {
  // 账号管理
  account: createAuthString('system.account', ['menu', 'create', 'update', 'delete', 'resetPassword']),
  // 角色管理
  role: createAuthString('system.role', ['menu', 'create', 'update', 'delete']),
  // 系统配置
  config: createAuthString('system.config', ['menu', 'create', 'update', 'delete'])
}

// 产品运营
const productOperation = {
  // 优惠卷
  discountCoupon: createAuthString('productOperation.discountCoupon', ['menu', 'create', 'update', 'delete']),
  // 充值活动
  recharge: createAuthString('productOperation.recharge', ['menu', 'create', 'update', 'delete'])
}

export default {
  dashboard,
  feedback,
  business,
  orders,
  productOperation,
  system
}
